function syncAllUsers() {
	$.ajax({
		url : "/syncAllUsers.do",
		success : function(result) {
			printMessage("All Users will be synced withing One Hour",
					"color:green;font-weight:bold;font-size:14px;")
		},
		error : function(result) {
			printMessage("Sync Service Unavailable. Please try again Later",
					"color:red;font-weight:bold;font-size:14px;")
		}

	});
}

function getUserList() {
	$.ajax({
		url : "/getUserList.do",
		success : function(result) {
			printMessage("User List should be avilable for download shortly",
					"color:green;font-weight:bold;font-size:14px;")
		},
		error : function(result) {
			printMessage("User List Generation Service Unavailable. Please try again Later",
					"color:red;font-weight:bold;font-size:14px;")
		}

	});
}



function generateReport(formId) {
	// var mailId = $("#mailTo").val();
	var canProceed = true;// isValidEmail(mailId);
	if (canProceed) {
		var formData = $(formId).serialize();
		$
				.ajax({
					url : "/generateReport.do",
					data : formData,
					type : "POST",
					success : function(result) {
						printMessage(
								"Report will be available for download shortly. Please revisit this page in about 30 minutes ",
								"color:green;font-weight:bold;font-size:14px;")
					},
					error : function(result) {
						printMessage(
								"Report Service Unavailable. Please try again Later",
								"color:red;font-weight:bold;font-size:14px;")
					}

				});
	} else {
		$("#errorMsg").html("Please provide a valid email");
		$("#mailTo").focus();
	}
}

function generateDetailedReportForm() {
	var elem = $("#detailReportForm").clone();
	$("#msg").html($(elem));
	$(elem).find(".cancel").click(reset);
	$(elem).find("#detailFromDate,#detailToDate").datepicker({changeMonth: true,changeYear: true, dateFormat: 'yy/mm/dd'});
	$(elem).show();
	
}

function generateReportForm() {
	var elem = $("#reportForm").clone();
	$("#msg").html($(elem));
	$(elem).find(".cancel").click(reset);
	$(elem).find("#fromDate,#toDate").datepicker({changeMonth: true,changeYear: true, dateFormat: 'yy/mm/dd'});
	$(elem).show();
}

function reset() {
	printMessage("Please Use the menus above", "");
}

function isValidEmail(email) {
	var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return regex.test(email);
}

function printMessage(msg, style) {
	$("#msg").html("<span style='" + style + "'>" + msg + "</span>")
}

function getImportForm() {
	var elem = $("#importForm").clone();
	$("#msg").html($(elem));
	$(elem).find(".cancel").click(reset);
	$(elem).show();
}